package org.reenscape.lib;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class Security {

  public synchronized String encrypt(String plaintext)
  {
    MessageDigest md = null;
    try
    {
      md = MessageDigest.getInstance("SHA"); //step 2
    }
    catch(NoSuchAlgorithmException e)
    {
    }
    try
    {
      md.update(plaintext.getBytes("UTF-8")); //step 3
    }
    catch(UnsupportedEncodingException e)
    {
    }

    byte raw[] = md.digest(); //step 4
    String hash = (new Base64Coder()).encode2(raw); //step 5
    return hash; //step 6
  }
  
  public boolean CheckPassword(String checking, String hash){
	String a2 = encrypt(checking);
	String b2 = hash;
	if(a2.equals(b2)) return true;
	else return false;
  }
}